/**
 * author:Administrator
 * date:2016/2/24
 * desc:TODO
 */

'use strict';

let seq = 1;
let list = {};

class ManagerRepoImpl {

  static * genId() {
    return 'mgr_' + (seq++);
  }

  static * find(id) {
    //console.log('all', list);
    return list[id];
  }

  /**
   * return pojo list
   * @param uId
   * @returns {*}
   */
  static * findByUid(uId) {
    let ids = Object.keys(list);
    let list = [];
    for (let id of ids) {
      let item = list[id];
      if (item.uId == uId) list.push(item);
    }
    return list;
  }

  static * store(mgr) {
    //console.log('ManagerRepoImpl store', mgr);
    if (!mgr.id) mgr.id = yield ManagerRepoImpl.genId();
    list[mgr.id] = mgr;
    //console.log('all', list);
  }

}
module.exports = ManagerRepoImpl;